#include "cpu/exec/helper.h"
#include "cpu/decode/modrm.h"

make_helper(nop) {
	print_asm("nop");
	return 1;
}

make_helper(int3) {
	void do_int3();
	do_int3();
	print_asm("int3");

	return 1;
}

make_helper(int_i_b) {
	uint8_t vec = instr_fetch(eip + 1, 1);
	/* Do not break; treat as no-op for PA2 so a single 'c' continues */
	print_asm("int $0x%x", vec);
	return 2;
}

make_helper(lea) {
	ModR_M m;
	m.val = instr_fetch(eip + 1, 1);
	int len = load_addr(eip + 1, &m, op_src);
	reg_l(m.reg) = op_src->addr;

	print_asm("leal %s,%%%s", op_src->str, regsl[m.reg]);
	return 1 + len;
}

//PA2-5 flag control
make_helper(cli) {
    cpu.eflags.IF = 0;
    print_asm("cli");
    return 1;
}

make_helper(sti) {
    cpu.eflags.IF = 1;
    print_asm("sti");
    return 1;
}

make_helper(cld) {
    cpu.eflags.DF = 0;
    print_asm("cld");
    return 1;
}

make_helper(std) {
    cpu.eflags.DF = 1;
    print_asm("std");
    return 1;
}

/* 0xD6: SALC sets AL = CF. Some toolchains emit this as filler. */
make_helper(salc) {
    cpu.gpr[0]._8[0] = cpu.eflags.CF ? 0xFF : 0x00; /* AL */
    print_asm("salc");
    return 1;
}